#include "../Header Files/CRenderer_AL.h"
#include "../Header Files/CRenderNode_AL.h"
#include "../Header Files/CSpriteNode_AL.h"
#include "../Header Files/Direct3D_AL.h"
#include "../Header Files/CCamera_AL.h"
#include "../Header Files/C3DNode_AL.h"

CRenderer_AL::CRenderer_AL()
{

}

CRenderer_AL::~CRenderer_AL()
{
}

CRenderer_AL* CRenderer_AL::GetInstance()
{
	static CRenderer_AL instance;
	return &instance;
}

void CRenderer_AL::Render(vector<CRenderNode_AL*>* _vRenderNodes, cCamera_AL* _pCamera)
{	
	Direct3D_AL::GetInstance()->m_pD3DDev->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(128, 128, 128), 1.0f, 0);
	Direct3D_AL::GetInstance()->m_pD3DDev->BeginScene();
	Direct3D_AL::GetInstance()->m_pSpriteManager->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT);

	if (_vRenderNodes->size() > 0)
	{

		for (unsigned int i(0); i < _vRenderNodes->size(); ++i)
		{
			switch ((*_vRenderNodes)[i]->GetRenderType())
			{
			case 0:
				{
				}
				break;
			case 1:
				{
					CSpriteNode_AL* temp = (CSpriteNode_AL*)((*_vRenderNodes)[i]);
					temp->Draw();
				}
				break;
			case 2:
			case 3:
				{
					C3DNode_AL* temp = (C3DNode_AL*)((*_vRenderNodes)[i]);
					temp->Draw(_pCamera);
				}
				break;
			}
		}
	}

	Direct3D_AL::GetInstance()->m_pSpriteManager->End();
	Direct3D_AL::GetInstance()->m_pD3DDev->EndScene();
	Direct3D_AL::GetInstance()->m_pD3DDev->Present(0, 0, 0, 0);
}

